import streamlit as st

from rag.pdf_demo import get_response_from_pdf

with st.sidebar:
    key = st.text_input("输入密钥")
    st.page_link(
        "https://bailian.console.aliyun.com/?spm=5176.28326591.0.0.40f76ee1vUR5Of&accounttraceid"
        "=d873c9fe82ea443d9f3170f30dd5690cfnng#/api_key",
        label="获取key", icon="🔑")

st.header("AI PDF")
file = st.file_uploader("上传pdf文件")
question = st.text_input("请先上传pdf文件再输入问题", disabled=not file)
flag = st.button("发送")
if flag and not key:
    st.info("请先输入密钥")
    st.stop()
if flag and not file:
    st.info("请先上传文件")
    st.stop()
if flag and question:
    with st.spinner("正在思考"):
        result = get_response_from_pdf(key, file, question)
        st.divider()
        st.write(result)
